%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 中国空间技术研究院学位论文与报告
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\CastDocumentType{MasterThesis}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 宏包
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 固定行距20磅,小四字体12磅,基础行距1.2倍, 20/12/1.2=1.389
\documentclass[AutoFakeBold,zihao=-4,linespread=1.389,fntef]{ctexbook}
\usepackage[a4paper]{geometry}  % \geometry
\usepackage{fancyhdr}  % \fancyhf,\fancyhead,\fancyfoot
\usepackage{setspace}  % spacing
\usepackage[numbers,sort&compress]{natbib}  % \bibsep

% \def\bibfont{\fontsize{10.5}{11.52}\selectfont}
% \setlength{\headheight}{15pt}
\setcitestyle{citesep={,\!}}  % 逗号后无空格
\setmainfont{Times New Roman}
\newcommand{\upcite}[1]{\textsuperscript{\cite{#1}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 页边距设置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\geometry{
    top=3.8cm,
    bottom=3.8cm,
    left=3.2cm,
    right=3.2cm,
    headsep=0.6cm,
    headheight=15pt,
    marginparsep=0cm,
    marginparwidth=0cm,
    bindingoffset=0cm,
    % showframe,
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 标题设置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ctexset{
contentsname = {\heiti\zihao{3}目\spacelong 录},
secnumdepth = 3,
tocdepth = 2,
chapter={  % 第2章
    name={第,章},
    number=\arabic{chapter},
    format=\heiti\fontsize{16}{16}\centering\selectfont,
    pagestyle=fancy,
    beforeskip=24pt,
    afterskip=24pt,
    fixskip=true,
},
section={  % 2.1
    format=\heiti\fontsize{14}{20}\selectfont,
    beforeskip=31pt,  % 24+(20-14)/2+(20-12)/2
    afterskip=13pt,   % 6+(20-14)/2+(20-12)/2
    fixskip=true,
},
subsection={  % 2.1.1
    format=\heiti\fontsize{13}{20}\selectfont,
    beforeskip=19pt,  % 12+(20-13)/2+(20-12)/2
    afterskip=13pt,   % 6+(20-13)/2+(20-12)/2
    fixskip=true,
},
subsubsection={  % 2.1.2.1
    format=\heiti\fontsize{12}{20}\selectfont,
    beforeskip=20pt,  % 12+(20-12)/2+(20-12)/2
    afterskip=14pt,    % 6+(20-12)/2+(20-12)/2
    fixskip=true,
},
paragraph={
    beforeskip=12pt,
    afterskip=12pt,
    fixskip=true,
},
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 固定长度与待填参数设置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\myspace[1]       {\par\vspace{#1\baselineskip}}
\newcommand\doublenofancy    {\clearpage{\thispagestyle{empty}\cleardoublepage}}
\newcommand\spaceshort       {\hspace{7.5pt}}  % 半个小三号字宽度
\newcommand\spacelong        {\hspace{15pt}}   % 一个小三号字宽度
\newcommand\spacefancy       {\hspace{10.5pt}}   % 一个五号字宽度，用于页眉的摘要和目录
\newcommand\spaceabstract    {\hspace{24pt}}   % 两个四号字宽度，用于关键词间的空格
\newlength{\lentitle}        \setlength{\lentitle}{225pt}
\newlength{\lenmsg}          \setlength{\lenmsg}{175pt}
\newlength{\TitleWidth}      \setlength{\TitleWidth}{8cm}
\newlength{\UnderLineDepth}  \setlength{\UnderLineDepth}{-.5em}
\newlength{\tabularspace}    \setlength{\tabularspace}{5pt}

\newcommand\atcntitle      {untitled}
\newcommand\atentitle      {untitled}
\newcommand\atschool       {untitled}
\newcommand\atmajor        {untitled}
\newcommand\atresearchdir  {untitled}
\newcommand\atadvisor      {untitled}
\newcommand\atadvititle    {untitled}
\newcommand\atstudent      {untitled}
\newcommand\atdatesubmit   {untitled}
\newcommand\atcnabstract   {untitled}
\newcommand\atenabstract   {untitled}
\newcommand\atcnkeyword    {untitled}
\newcommand\atenkeyword    {untitled}

\newcommand\cntitle[1]     {\renewcommand\atcntitle{#1}}
\newcommand\entitle[1]     {\renewcommand\atentitle{#1}}
\newcommand\school[1]      {\renewcommand\atschool{#1}}
\newcommand\major[1]       {\renewcommand\atmajor{#1}}
\newcommand\researchdir[1] {\renewcommand\atresearchdir{#1}}
\newcommand\student[1]     {\renewcommand\atstudent{#1}}
\newcommand\datesubmit[1]  {\renewcommand\atdatesubmit{#1}}
\newcommand\advisor[2]     {\renewcommand\atadvisor{#1}\renewcommand\atadvititle{#2}}
\newcommand\cnabstract[1]  {\renewcommand\atcnabstract{#1}}
\newcommand\enabstract[1]  {\renewcommand\atenabstract{#1}}
\newcommand\cnkeyword[1]   {\renewcommand\atcnkeyword{#1}}
\newcommand\enkeyword[1]   {\renewcommand\atenkeyword{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 中英文摘要和个人简历
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\cnabstractcontent{
    \chapter*{摘\spacefancy 要}
    \fancyhead[C]{\zihao{5}\selectfont 摘要}
    \atcnabstract
    \\[20pt]\textbf{关键词：}\atcnkeyword
}
\newcommand\enabstractcontent{
    \ctexset{chapter/format=\fontsize{16}{16}\centering\setmainfont{Arial}}
    \chapter*{Abstract}
    \fancyhead[C]{\zihao{5}\selectfont Abstract}
    \atenabstract
    \\[20pt]\textbf{Keywords：}\atenkeyword
}
\newenvironment{resume}[1]{
    \ctexset{chapter/numbering=false}
\chapter{#1}}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 固定列宽、内容居中、自动换行、且有下画线
% https://ask.latexstudio.net/ask/question/3650.html
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\LongTitle[1]{
\begin{center}
    \begin{tabular}{rp{\TitleWidth}}
      \zihao{3}
      \textbf{论文题目}： & 
      \begin{linenumbers*}
        \internallinenumbers
        \renewcommand\makeLineNumber{
        \hss\linenumberfont\hskip\linenumbersep
          \tikz[remember picture,overlay]
          \draw (0,\UnderLineDepth) -- (\TitleWidth,\UnderLineDepth);}
        \begin{centerlastline}
          \zihao{3}\hphantom{}{\textbf{#1}}
        \end{centerlastline}
      \end{linenumbers*}\\
    \end{tabular}
\end{center}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 目录格式设置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fancyhf{}
\pagestyle{fancy}
% \renewcommand*\contentsname{\hfill \heiti\zihao{3}目\spacelong 录 \hfill}
% \setlength{\cftbeforetoctitleskip}{20pt}
% \setlength{\cftaftertoctitleskip}{20pt}
% \setlength\cftbeforechapskip{6pt}
% \setlength\cftafterchapskip{0pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 封面
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\makecover{
    \newgeometry{top=2cm,bottom=5.5cm,left=4cm,right=4cm,headsep=0cm,headheight=0cm}
    \thispagestyle{empty}
    \hspace{-22pt}\includegraphics[scale=0.08]{cascicon.jpg}
    \vspace{35pt}
    \begin{center}\zihao{1}\linespread{1.25}\heiti\selectfont\atcntitle\end{center}
    \begin{center}\fontsize{20}{25}\setmainfont[BoldFont={Arial Bold}]{Arial}\selectfont\textbf{\atentitle}\end{center}
    \begin{center}\zihao{-2}(申请中国空间技术研究院工学博士学位论文)\end{center}
    \vspace{20pt}
    \begin{flushleft}
        \hspace{50pt}\fangsong\zihao{3}培养单位\ ：\ \atschool \\
        \hspace{50pt}\fangsong\zihao{3}专\spacelong\spacelong 业\ ：\ \atmajor \\
        \hspace{50pt}\fangsong\zihao{3}研究方向\ ：\ \atresearchdir \\
        \hspace{50pt}\fangsong\zihao{3}研\spaceshort 究\spaceshort 生\ ：\ \atstudent \\
        \hspace{50pt}\fangsong\zihao{3}导\spacelong\spacelong 师\ ：\ \atadvisor\spacelong\atadvititle \\
    \end{flushleft}
    \vfill
    \begin{center}\songti\zihao{3}\atdatesubmit\end{center}
    \doublenofancy
    \restoregeometry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 原创性声明、授权书
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\makeauthorization{
    \fancyhead[c]{原创声明、授权书}\fancyfoot[c]{}
    \begin{center}\heiti\zihao{-2}\selectfont 博士学位论文原创性声明\end{center}\par
    本人郑重声明：本人所提交的博士学位论文《\uline{\atcntitle}》，是在导师指导下独立进行研究所取得的成果。该学位论文中凡引用他人已经发表或未发表的成果、数据、观点等，均已注明出处。除论文中已经注明引用的内容外，不包含任何其他个人或集体已经发表或撰写过的科研成果。对本文的研究工作做出重要贡献的个人和集体，均已在文中以明确方式注明。\par
    本声明的法律结果由本人承担。\vspace{15pt}
    \begin{flushright}论文作者签名：\underline{\makebox[80pt]{}}日期：\underline{\makebox[80pt]{}}\end{flushright}
    \vspace{20pt}
    \begin{center}\heiti\zihao{-2}\selectfont 博士学位论文使用授权书\end{center}\par
    本人在导师指导下所完成的学位论文《\uline{\atcntitle}》及相关的研究成果，其知识产权归属中国航天科技集团公司五院五〇二研究所（北京控制工程研究所）。本人完全了解五〇二研究所（北京控制工程研究所）有关保存、使用学位论文的规定，同意五〇二研究所（北京控制工程研究所）保存或向国家有关部门或机构送交论文的纸质版和电子版，允许论文被查阅和借阅；本人授权五〇二研究所（北京控制工程研究所）可以将本学位论文的全部或部分内容编入有关数据库进行检索，可以采用任何复制手段保存和汇编本学位论文。本人离所后发表、使用本学位论文或与该论文直接相关的学术论文或成果时，第一署名单位仍然为五〇二研究所（北京控制工程研究所）。\par
    涉密论文在解密后要遵守此规定。\vspace{15pt}
    \begin{flushright}
    论文作者签名：\underline{\makebox[80pt]{}}日期：\underline{\makebox[80pt]{}}
    \\ \vspace{20pt}
    导师签名：\underline{\makebox[80pt]{}}日期：\underline{\makebox[80pt]{}}
    \end{flushright}
    \cleardoublepage
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 摘要、目录
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\maketemplate{
    \makecover
    \makeauthorization
    \pagenumbering{Roman}\fancyhead[c]{\leftmark}\fancyfoot[c]{\thepage}
    \cnabstractcontent
    \enabstractcontent
    \cleardoublepage\fancyhead[c]{目\spacefancy 录}
    \begin{spacing}{1.37}
    \tableofcontents
    \end{spacing}
    \mainmatter
    \pagenumbering{arabic}\fancyhead[c]{\leftmark}\fancyfoot[c]{\thepage}
}
